package hadlers

import (
	"dev-manage/modles"
	"github.com/gin-gonic/gin"
	"strconv"
)

func OrderAdd(c *gin.Context) {
	orderName := c.PostForm("orderName")
	orderAuthor := c.PostForm("orderAuthor")

	if orderName == "" || orderAuthor == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}

	var data = modles.Order{
		OrderName:   orderName,
		OrderAuthor: orderAuthor,
	}

	modles.DB.Debug().Create(&data)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": data,
	})
	return
}

func OrderList(c *gin.Context) {
	page, _ := strconv.Atoi(c.Query("page"))
	size, _ := strconv.Atoi(c.Query("size"))
	offset := (page - 1) * size

	var data []modles.Order
	modles.DB.Debug().Offset(offset).Limit(size).Find(&data)

	var total int64
	modles.DB.Model(&modles.Order{}).Count(&total)
	c.JSON(200, gin.H{
		"code":  200,
		"msg":   "ok",
		"data":  data,
		"count": total,
	})
	return
}

func OrderDetail(c *gin.Context) {

}
